﻿namespace jQube.Web
{
    using System;
    using System.Collections;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;

    internal class PageWrapper : IPage
    {
        public PageWrapper(Page page)
        {
            this.Page = page;
        }

        public Page Page { get; private set; }

        #region Miembros de IPage

        string IPage.AppRelativeVirtualPath
        {
            get { return this.Page.AppRelativeVirtualPath; }
        }

        IClientScriptManager IPage.ClientScript
        {
            get { return new ClientScriptWrapper(this.Page.ClientScript); }
        }

        bool IPage.EnableEventValidation
        {
            get { return this.Page.EnableEventValidation; }
            set { this.Page.EnableEventValidation = value; }
        }

        IHtmlForm IPage.Form
        {
            get
            {
                if (this.Page.Form != null)
                {
                    return new HtmlFormWrapper(this.Page.Form);
                }

                return null;
            }
        }

        HtmlHead IPage.Header
        {
            get { return this.Page.Header; }
        }

        bool IPage.IsPostBack
        {
            get { return this.Page.IsPostBack; }
        }

        IDictionary IPage.Items
        {
            get { return this.Page.Items; }
        }

        IHttpRequest IPage.Request
        {
            get { return new HttpRequestWrapper(this.Page.Request); }
        }

        IHttpResponse IPage.Response
        {
            get { return new HttpResponseWrapper(this.Page.Response); }
        }

        IHttpServerUtility IPage.Server
        {
            get { return new HttpServerUtilityWrapper(this.Page.Server); }
        }

        string IPage.Title
        {
            get { return this.Page.Title; }
        }

        event EventHandler IPage.Error
        {
            add { this.Page.Error += value; }
            remove { this.Page.Error -= value; }
        }

        event EventHandler IPage.InitComplete
        {
            add { this.Page.Init += value; }
            remove { this.Page.Init -= value; }
        }

        event EventHandler IPage.PreRender
        {
            add { this.Page.PreRender += value; }
            remove { this.Page.PreRender -= value; }
        }

        event EventHandler IPage.PreRenderComplete
        {
            add { this.Page.PreRenderComplete += value; }
            remove { this.Page.PreRenderComplete -= value; }
        }

        Control IPage.FindControl(string id)
        {
            return this.Page.FindControl(id);
        }

        void IPage.SetFocus(Control control)
        {
            this.Page.SetFocus(control);
        }

        void IPage.SetFocus(string clientID)
        {
            this.Page.SetFocus(clientID);
        }

        void IPage.SetRenderMethodDelegate(RenderMethod renderMethod)
        {
            this.Page.SetRenderMethodDelegate(renderMethod);
        }

        string IPage.ResolveClientUrl(string relativeUrl)
        {
            return this.Page.ResolveClientUrl(relativeUrl);
        }

        void IPage.VerifyRenderingInServerForm(Control control)
        {
            this.Page.VerifyRenderingInServerForm(control);
        }

        #endregion
    }
}
